<template>
  <div class="home">
    <el-container class="home-container">
      <el-header>
        <div class="left">
          <img src="../assets/lyf.jpg">
          <span>帅哥管理大师系统</span>
        </div>
        <el-button @click="loginout">退出</el-button>
      </el-header>
      <el-container>
        <el-aside :width="isColl ? '64px':'200px'">
          <div class="toggleMenu" @click="isColl = !isColl">
            |||
          </div>
          <!-- 侧边栏菜单 -->
          <el-menu background-color="#373834" text-color="#fff" active-text-color="#1a94bc" :unique-opened= true :collapse="isColl" :collapse-transition= false :default-active= "activeIndex" :router="true">
             <el-submenu :index="item.id + ''" v-for="item in menulist" :key="item.id">
               <template slot="title">
               <i :class="iconsObj[item.id]"></i>
               <span>{{item.authName}}</span>
             </template>
              <el-menu-item :index="'/' + item1.path" v-for="item1 in item.children" :key="item1.id">
                <i class="el-icon-menu"></i>
                <span>{{item1.authName}}</span>
              </el-menu-item>
          </el-submenu>
           </el-menu>
        </el-aside>
        <el-main>
          <router-view/>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>

export default {
  data () {
    return {
      menulist: [],
      iconsObj: {
        125: 'iconfont icon-users',
        103: 'iconfont icon-morentouxiang',
        101: 'iconfont icon-shangpin',
        102: 'iconfont icon-lock_fill',
        145: 'iconfont icon-danju'
      },
      isColl: false,
      activeIndex: ''
    }
  },
  created () {
    this.getMenus()
    this.activeIndex = this.$route.path
  },

  methods: {
    loginout () {
      sessionStorage.removeItem('token')
      this.$router.go('/login')
    },
    async getMenus () {
      const { data: res } = await this.axios.get('menus')
      if (res.meta.status !== 200) return this.$message.error('获取数据失败')
      this.menulist = res.data
      // console.log(res)
    }
  }

}
</script>
<style lang="less">
.home-container {
  height: 100%;
  .el-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #2b312c;
    height: 80px !important;
    .left {
      margin: 10px;
      img {
        vertical-align: middle;
        width: 60px;
        height: 60px;
        border-radius: 50%;
      }
      span {
        margin-left: 10px;
        color: #fff;
        font-size: 24px;
        // font-weight: 700;
      }
    }
    .el-button {
     float: right;
     margin: 15px;
     height: 40px !important;
    }
  }
  .el-aside {
    // height: 100%;
    overflow: auto;
    flex-shrink: 0;
    background-color:#2b312c;
    .toggleMenu {
      width: 100%;
      height: 40px;
      text-align: center;
      line-height: 40px;
      background-color: #8cc269;
      letter-spacing: 0.5em;
      cursor: pointer;
      user-select: none;
      color: #fff;
    }
    .el-menu {
      border-right: none;
    }
    .el-submenu span {
      padding-left: 8px;
    }
  }
}
</style>
